<?php

class LoginController extends UserBaseC {

    /**
     * Declares class-based actions.
     */
    public $layout = 'theme.views.layouts.FrontLogoHeaderContent';
    public $sina_url = null;
    public $qq_url = null;

    public function actionLogin() {
        if (Yii::app()->user->id) {
            $this->redirect(array("/user/info/index"));
        }
        $model = new LoginForm();
        // if it is ajax validation request
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }
        // collect user input data
        if (isset($_POST['LoginForm'])) {
            $model->attributes = $_POST['LoginForm'];
            if ($model->validate() && $model->login()) {
                if (Yii::app()->user->status == 0) {
                    Yii::app()->user->logout();
                    $email = urlencode(Yii::app()->user->email);
                    $this->redirect(array("/user/user/regemailsuccesed", 'mail' => $email));
                }
                $cookie = Yii::app()->request->getCookies();
                $jump = $cookie['jump']->value;
                unset($cookie['jump']);
                if (empty($jump)) {
                    if (yii::app()->user->kind == 0) {
                        $jump = $this->createUrl('bm/bm');
                    } else {
                        $jump = Yii::app()->user->returnUrl;
                    }
                }
                $this->redirect($jump);
            }
        }
        UrlClass::returnUrl('/user/login/login');

        // display the login form
        $this->render('login', array('model' => $model));
    }

}
